/**
 * 处理 user 相关的操作
 */

import ajax from '@/utils/request';

/**
* 用户登录
* @param {*} mobile 手机号
* @param {*} code 验证码
*/
export const userLogin = (mobile, code) => {
  return ajax({
    method: 'POST',
    url: '/app/v1_0/authorizations',
    data: {
      mobile,
      code
    }
  });
};

/**
 * 获取用户信息
 * 私人信息，手机号...
 */
export const userGetInfo = () => {
  return ajax({
    method: 'GET',
    url: '/app/v1_0/user/profile'
  });
};

/**
 * 关注用户
 * @param {*} userId 用户id
 */
export const followUser = userId => {
  return ajax({
    method: 'POST',
    url: '/app/v1_0/user/followings',
    data: {
      target: userId
    }
  });
};

/**
 * 取消关注用户
 * @param {*} userId 用户id
 */
export const unfollowUser = userId => {
  return ajax({
    method: 'DELETE',
    url: '/app/v1_0/user/followings/' + userId
  });
};

/**
 * 获取用户自己信息
 * 社交信息，粉丝数，关注数...
 */
export const getInfo = () => {
  return ajax({
    method: 'GET',
    url: '/app/v1_0/user'
  });
};

/**
 * 修改用户信息
 * @param {*} data name，gender，birthday
 */
export const updateUserInfo = data => {
  return ajax({
    method: 'PATCH',
    url: '/app/v1_0/user/profile',
    data
  });
};

/**
 * 修改用户头像
 * @param {*} formData formData格式的对象
 */
export const updatePhoto = formData => {
  return ajax({
    method: 'PATCH',
    url: '/app/v1_0/user/photo',
    data: formData
  });
};
